package org.i1510.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.i1510.common.bean.PageBean;
import org.i1510.common.dao.ISysLogDao;
import org.i1510.common.po.SysLog;
import org.i1510.common.service.ISysLogService;
import org.i1510.common.utils.BeanUtils;
import org.i1510.common.utils.web.ResultMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("iSysLogService")
public class SysLogServiceImpl extends BaseServiceImpl implements
		ISysLogService {
	@Autowired
	private ISysLogDao iSysLogDao;

	@Transactional
	public ResultMapper saveAll(List<SysLog> list) {

		ResultMapper mapper = ResultMapper.generateFailure();

		List<SysLog> listSaved = iSysLogDao.save(list);
		
		if (listSaved == null) {
			return null;
		}
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", listSaved);
		return mapper;
	}

	public ResultMapper save(SysLog basePo) {

		ResultMapper mapper = ResultMapper.generateFailure();
		SysLog saved = iSysLogDao.save(basePo);
		if (saved == null) {
			return null;
		}	
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", saved);
		return mapper;
	}
	public ResultMapper delete(String fdId) {

		ResultMapper mapper = ResultMapper.generateFailure();
		iSysLogDao.delete(fdId);
		mapper = ResultMapper.generateSuccess();
		return mapper;
	}
	
	public SysLog findById(String fdId){
		SysLog  SysLog = iSysLogDao.findById(fdId);
		return SysLog;
	}
	public List<SysLog> findByIds(List<String> fdIds){
		return (List<SysLog>) iSysLogDao.findAll(fdIds);
	}
	public List getPage(SysLog sysLog, PageBean pageBean,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysLog, map);
		map.put("intPageIndex", pageBean.getIntPageIndex());
		map.put("intPageSize", pageBean.getIntPageSize());
		map.putAll(conditions);
		List list = this.queryForListBySql("sysLogSql.getPage", map);
		return list;
	}

	public int getPageCount(SysLog sysLog,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysLog, map);
		map.putAll(conditions);
		List list = this.queryForListBySql("sysLogSql.getPageCount", map);
		return list.size();
	}

}
